#include<stdio.h>
#include<assert.h>
#include<string.h>
int my_strlen(const char *str){
  assert(str);
  int ret = 0;
  while(*str!='\0'){
    ret++;
    str++;
  }
  return ret;
}
char* my_strcpy(char* dest,const char* src){
  assert(dest&&src);
  char * ret = dest;
  while(*dest++ = *src++){
    ;
  }
  return ret;
}
char* my_strcat(char* dest,const char *src){
  assert(dest&&src);
  char* ret = dest;
  while(*dest){
    dest++;
  }
  while(*dest++=*src++){
    ;
  }
  return ret;
}
int my_strcmp(const char* src,const char* dest){
  assert(src && dest);
  while(*src++==*dest++){
    if(*src=='\0'){
      return 0;
    }
  }
  return *src-*dest;
}
char* my_strstr(const char* str1,const char* str2){
  assert(str1&&str2);
    const char* s1 = str1;
    const char* cur = str1;
    const char* s2 = str2;
    while(*cur){
      s1 = cur;
      s2 = str2;
      while(*s1 && *s2 && (*s1==*s2)){
        s1++;
        s2++;
      }
      if(*s2=='\0'){
          return (char*)cur;
        }
        cur++;
    } 
    return NULL;
  }
  char *strstr(const char* str1,const char* str2){
    assert(str1 && str2);
     char* s1 = (char *)str1;
     char* cur = (char *)str1;
     char* s2 = (char*)str2;
    while(*cur){
      s1 = cur;
      s2 = (char*)str2;
      while (*s1 && *s2 && (*s1==*s2))
      {
        s1++;
        s2++;
      }
      if(*s2=='\0'){
          return (char *)cur;
        }
      cur++;
    }
    return NULL;
  }
  char *my_memcpy(void* dest,void* src,size_t count){
    assert(dest && src);
    void *ret = dest;
    while(count--){
      *(char*)dest = *(char*)src;
      dest = (char*)dest+1;
      src = (char*)src+1;
    }
    return ret;
  }
  char* my_memmove(void* dest,void* src,size_t count){
    assert(dest && src);
    void* ret = dest;
    if(dest<src){
      while(count--){
        *(char*)dest = *(char*)src;
        dest = (char*)dest+1;
        src = (char*)src+1;
      }
    }
    else{
      while(count--){
        *((char*)dest +count-1) = *((char*)src +count-1);
      }
    }
    return ret;
  }
int main(){
  char arr1[] = "abcdef";
  char arr2[] = "bcde";
  int arr3[] = {1,2,3,4,5,6,7,8};
  int arr4[] ={3,2,1};
  int ret1 = my_strlen(arr1);
  int ret2 = my_strlen(arr2);
  void* ret = my_memmove(arr3+3,arr3+1,16);
  for (int i = 0; i < 8; i++)
  {
    printf("%d ",arr3[i]);
  }
  
  char* ret3 = my_strcat(arr1,arr2);
  // printf("%s\n",arr1);
  // printf("%s\n",arr2);
  int ret5 = my_strcmp(arr1,arr2);
  char *ret4 = my_strstr(arr1,arr2);
  // printf("%s\n",ret3);
}